<template>
	<div class="box">
		<!-- <div class="wxindex">页面登录中，请稍后……</div> -->
	</div>
</template>
<script>
	export default {
		data() {
			return {
				token: null,
			};
		},
		created() {
			let _this = this;
			//测试登录
			this.$cookie.set(process.env.VUE_APP_BASE_TOKEN, 'A_WXGZHOPENID_ovSKeweKLy-x0dFEdPAXH7pFjgIk', 1);		//测试登录
			let token = this.$cookie.get(process.env.VUE_APP_BASE_TOKEN);
			if(token){
				//有token
				_this.$router.replace('/home')
			}
			
			
			// 用于自己人不同token调试
			// let token = this.$route.query.token;
			// if(token){
			//   this.$cookie.set(isCookieName,token,1);
			// 	this.$router.replace('/home')
			// }else {
			// 	// 获取钉钉的code码并登录
			// 	this.getDDCode()
			// }
		},
		methods: {
			// 获取钉钉的code码
			getDDCode(){
				let _this = this
				dd.getAuthCode({corpId: ""}).then((result) =>{
				    if (result) {
								// alert(result.code)
								// 将钉钉的code传入后台获取token
								_this.setCodeToken(result.code)
				    }
				})
			},
			// 将钉钉的code传入后台获取token
			setCodeToken(code){
				let _this = this;
				// 自定义加载图标
				_this.$indicator.open();
				let formData = new FormData();
				formData.append('authCode',code)
				_this.$http({
					method: 'post',
					url: LINKURL + 'zzd/login',
					data:formData,
					headers:{"Content-Type":"multipart/form-data"}
				})
				.then(function(json){
					_this.$indicator.close();
					if(json.data.result == 1){
						// _this.$toast('提交成功');
						let data = json.data.data;
						
						let cqtToken = data.token			// token
						let accountId = data.accountId 			// 浙政钉账号id
						let lastName = data.lastName 				// 姓名
						if(cqtToken){
							_this.$cookie.set(process.env.VUE_APP_BASE_TOKEN, cqtToken, 1);
							//有token
							_this.$router.replace('/home')
						}
						if(accountId){
							
							aplus_queue.push({
								action: "aplus.setMetaInfo",
								arguments: ["_user_nick", lastName]
							});
							//设置会员ID  accountId
							aplus_queue.push({
								action: "aplus.setMetaInfo",
								arguments: ["_user_id", accountId]
							});
							aplus_queue.push({
								action: "aplus.setMetaInfo",
								arguments: ["_dev_id", "yourDeviceId"]
							});
							
						}
						if(accountId){
							dd.setStorageItem({
							    name: "accountId1",
							    value: accountId
							}).then(res => {
							  console.log(res)
							}).catch(err => {})
							dd.setStorageItem({
							    name: "lastName1",
							    value: lastName
							}).then(res => {
							  console.log(res)
							}).catch(err => {})
							// _this.$cookie.set('accountId1', accountId, 1);
							// _this.$cookie.set('lastName1', lastName, 1);
						}
					}else{
						_this.$toast(json.data.errorcode);
					}
				})
				.catch(function(err){
					_this.$indicator.close();
				})
			},
			// 获取页面参数
			getQueryString(name) {
				let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				let r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]); return null;
			},
		}
	};
</script>
<style scoped>
	.box {
		height: 100vh;
		width: 100%;
		background-color: #FFFFFF;
	}
	.wxindex {
		padding-top: 4rem;
		font-size: 0.28rem;
		text-align: center;
	}
</style>
